package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.Category;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author: qingtao
 * @Date 2022/3/10 8:51
 */
public interface CategoryMapper {

    /**
     * 修改
     * @param category
     * @return
     */
    Integer update(Category category);

    /**
     * 删除
     * @param id 条件
     * @return
     */
    @Delete("delete from category where id=#{id}")
    Integer delete(Long id);

    /**
     * 分页查询
     * @return
     */
    @Select("select * from category order by sort")
    List<Category> findAll();

    /**
     * 添加分类
     * @param category
     * @return
     */
    @Insert("insert into category values (null,#{type},#{name}," +
            "#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    Integer save(Category category);

    /**
     * 根据名字查询
     * @param category
     * @return
     */
    @Select("select * from category where `name`=#{name}")
    Category getByName(Category category);

    /**
     * 根据类型查询
     * @param type
     * @return
     */
    List<Category> findAllByType(@Param("type") Integer type);

    /**
     * 根据id查
     * @param id
     * @return
     */
    @Select("select * from category where id=#{id}")
    Category findAllById(@Param("id") Long id);

}
